<?php
######################################################################
#
# LOGOUT DO SISTEMA ( direciona para index.php )
# Empresa: ATI
# Autor:   James Cleyton
# Nome:    logout.php
#
######################################################################

include("config.php");
include($config["Inclusoes"]."/db.php");
include($config["Piau"]."/kernel/funcoes_sistema.php");

if ($config["Manutencao"]) {
   header("Location: ".$config["URL"].$config["Diretorio"]."/index.php");
   exit;
}

session_name($config["Nome_Sessao"]);
session_start();
if (!isset($_SESSION["sessao"])) {
   $sessao = array();
   $sessao["nome"]="";
   $sessao["logado"]=false;
   $sessao["erro"]="";
   $sessao["pid"]="0";
   $sessao["mascara"]="";
   $sessao["conexao"]="";
   $sessao["acesso"]="0";
}
else {
   $sessao = $_SESSION['sessao'];
   $login = $sessao["nome"];
   if (isset($config["Temporario"]))
      grava_arquivo($config["Temporario"]."/acesso_piau_novo","OUT:$login");
   else
      grava_arquivo("/tmp/acesso_piau_novo","OUT:$login SIS:".$config["Sistema"]);
   $sql = new BD_class;         //Objeto de acesso ao Banco de Dados
   $sql->Create($config["BD"]);
   list($conexao,$acesso) = $sql->QueryRow("Select conexao,acesso from sessao where id='".session_id()."' ");
   if ($conexao>0)
      grava_acesso_sublog($sql,$conexao,($acesso+1),0,'O','LOGOUT');
}

encerra_tempo_sessao(); //Exclui contangem de tempo da sessao

unset($_SESSION["sessao"]);
session_destroy();
header("Location: ".$config["URL"].$config["Diretorio"]."/index.php");
?>
